package com.GlobalPaint.app.ui.location;

import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.GlobalPaint.app.Base.FragmentAdapter;
import com.GlobalPaint.app.R;
import com.GlobalPaint.app.utils.MyViewPager;

import java.util.ArrayList;
import java.util.List;

public class LocationFragment extends Fragment implements View.OnClickListener{
    private MyViewPager mViewPagerChart;//viewpager
    private MyLocationFragment locationFragment;
    private MyFriendsFragment friendsFragment;
    private TextView bt_weizhi;
    private TextView bt_haoyou;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {

        View view=inflater.inflate(R.layout.fragment_location, container, false);
        initView(view);
        return view;
    }

    private void initView(View view) {
        locationFragment = new MyLocationFragment();
        friendsFragment = new MyFriendsFragment();
        mViewPagerChart = (MyViewPager)view.findViewById(R.id.view_pager_chart);
        bt_weizhi = (TextView)view. findViewById(R.id.bt_weizhi);
        bt_haoyou = (TextView)view.findViewById(R.id.bt_haoyou);
        bt_haoyou.setOnClickListener(this);
        bt_weizhi.setOnClickListener(this);
        //初始化TabLayout的title数据集
        List<String> titles = new ArrayList<>();
        titles.add("");
        titles.add("");
        //初始化ViewPager的数据集
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(locationFragment);
        fragments.add(friendsFragment);
        //创建ViewPager的adapter
        FragmentAdapter adapter = new FragmentAdapter(getChildFragmentManager(), fragments, titles);
        mViewPagerChart.setAdapter(adapter);
        mViewPagerChart.setCurrentItem(0);
        mViewPagerChart.setOffscreenPageLimit(2);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.bt_weizhi:
                bt_weizhi.setTextColor(Color.rgb(37, 168, 37));
                bt_weizhi.setTextSize(17);
                bt_haoyou.setTextSize(15);
                bt_haoyou.setTextColor(Color.rgb(144, 144, 144));
                mViewPagerChart.setCurrentItem(0);
                break;
            case R.id.bt_haoyou:
                bt_weizhi.setTextColor(Color.rgb(144, 144, 144));
                bt_haoyou.setTextSize(17);
                bt_weizhi.setTextSize(15);
                bt_haoyou.setTextColor(Color.rgb(37, 168, 37));
                mViewPagerChart.setCurrentItem(1);
                break;
        }
    }
}
